# -*- coding：utf-8 -*-
"""
@Time:2024-10-0614:37
@Auth:泛彼泊舟
@File:atest_shopxo.py
@IDE:PyCharm
@模块功能：xxx
"""
import jsonpath
from common.request.requests_util import RequestUtil
from common.yaml.yaml_Util import write_yaml, read_yaml


class TestShopxo:
    # sess = requests.session()  # 保持同一个session
    # 开始列表
    def test_start_list(self):
        method = "post"
        url = "http://101.34.221.219:8010/api.php"
        params = {
            "token": "token",
            "ajax": "ajax",
            "s": "index/index"
        }
        res = RequestUtil().send_all_request(method=method, url=url, params=params)
        print(res.json())

    # 商品详情
    def test_product_detail(self):
        method = "post"
        url = "http://101.34.221.219:8010/api.php"
        params = {
            "s": "goods/detail"
        }

        json = {
                "goods_id": "12"
        }
        res = RequestUtil().send_all_request(method=method, url=url, params=params, json=json)
        print(res.json())

    # 登录接口
    def test_login_shopxo(self):
        method = "post"
        url = "http://101.34.221.219:8010/api.php"
        params = {
                "token": "token",
                "s": "user/login"
        }

        json = {
            "accounts": "baili",
            "pwd": "baili123",
            "verify": "rib5",
            "type": "username"
        }
        res = RequestUtil().send_all_request(method=method, url=url, params=params, json=json)
        print(res.json())
        # 提取token
        data = {"token": jsonpath.jsonpath(res.json(), "$.data.token")[0]}
        write_yaml(data)



    # 订单列表
    def test_order_list(self):
        method = "post"
        url = "http://101.34.221.219:8010/api.php"
        params = {
            "token": read_yaml("token")
            ,
            "s": "order/index"
        }

        json = {
            "page": 1,
            "keywords": "",
            "status": "-1",
            "is_more": 1
        }
        print(params)
        res = RequestUtil().send_all_request(method=method, url=url, params=params, json=json)
        print(res.json())

    # 订单详情
    def test_order_detail(self):
        method = "post"
        url = "http://101.34.221.219:8010/api.php"
        params = {
            "token": read_yaml("token"),
            "s": "order/detail"
        }

        json = {
            "id": "5070"
        }
        print(params)
        res = RequestUtil().send_all_request(method=method, url=url, params=params, json=json)
        print(res.json())


